package cn.sh.cares.tools.srcgen.generate;

public class DefaultNameConverter implements NameConverter {

	public String generateJavaClass(String tableName) {
		StringBuilder sb = new StringBuilder();
		
		String[] splits = tableName.toLowerCase().split("_");
		for (String split : splits) {
			if ("".equals(split)) {
				continue;
			}
			sb.append(split.substring(0, 1).toUpperCase());
			sb.append(split.substring(1));
		}
		return sb.toString();
	}

	public String generateJavaProperty(String columnName) {
		StringBuilder sb = new StringBuilder();
		
		String[] splits = columnName.toLowerCase().split("_");
		for (String split : splits) {
			if ("".equals(split)) {
				continue;
			}
			sb.append(split.substring(0, 1).toUpperCase());
			sb.append(split.substring(1));
		}

		sb.replace(0, 1, sb.substring(0, 1).toLowerCase());
		
		if ("switch".equalsIgnoreCase(sb.toString())) {
			return "switchFlag";
		}
		return sb.toString();
	}

}
